package xdu.lz.stage4_atomic.chapter6_aomicxxxFieldUpdater;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/**
 * Created at 2019/10/17 0017 下午 8:54
 */
public class IntegerFiledUpdater {

    private volatile Integer i = 0;

    public static void main(String[] args) {
        IntegerFiledUpdater test = new IntegerFiledUpdater();
        AtomicIntegerFieldUpdater<IntegerFiledUpdater> updater =
                AtomicIntegerFieldUpdater.newUpdater(IntegerFiledUpdater.class,"i");
        int i = updater.incrementAndGet(test);
        int i1 = updater.addAndGet(test, 5);
        System.out.println(i);
        System.out.println(i1);
    }
}
